package com.select.course.controller;

import com.select.course.entity.SchoolMajor;
import com.select.course.service.SchoolMajorService;
import com.select.course.utils.PageUtils;
import com.select.course.utils.R;
import com.select.course.vo.MajorVo;
import com.select.course.vo.PageVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
@CrossOrigin
@RestController
@RequestMapping("/major")
public class SchoolMajorController {

    @Resource
    private SchoolMajorService schoolMajorService;

    @GetMapping("/getmajorinfo/{majorid}")
    public R getMajorInfo(@PathVariable String majorid) {
        MajorVo majorVo = schoolMajorService.getMajorInfo(majorid);

        return R.ok().put("data",majorVo);
    }

    //getmajorgroup
    @GetMapping("getmajorgroup")
    public R getMajorGroup() {
        List<SchoolMajor> schoolMajors = schoolMajorService.getMajorName();

        return R.ok().put("data",schoolMajors);
    }
    @GetMapping("/getmajor/{value}")
    public R getMajor(@PathVariable(value = "value") String name) {
        List<MajorVo> classList = schoolMajorService.getMajorByCollegeName(name);

        return R.ok().put("data",classList);
    }

    @PostMapping("/getmajorpage")
    public R getMajorPage(@RequestBody PageVo pageVo) {
        PageUtils pageUtils = schoolMajorService.getMajorPage(pageVo);
        return R.ok().put("data",pageUtils);
    }

    @PostMapping("/addmajor")
    public R addMajor(@RequestBody MajorVo majorVo) {
        R r = schoolMajorService.addMajor(majorVo);
        return r;
    }

    @DeleteMapping("/deletemajor/{id}")
    public R deleteMajor(@PathVariable Long id) {
        schoolMajorService.deleteMjor(id);
        return R.ok();
    }

    @PutMapping("/updatemajor")
    public R updateMajor(@RequestBody MajorVo majorVo) {
        R r = schoolMajorService.updateMajor(majorVo);

        return R.ok();
    }
}
